package com.zlzxm.shoesmarket.viewmodel;

import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zlzxm.shoesmarket.net.BaseCallBack;
import com.zlzxm.shoesmarket.net.repository.WareRepository;
import com.zlzxm.shoesmarket.net.request.RqWareUpdate;
import com.zlzxm.shoesmarket.util.RxAndroidHelp;
import com.zlzxm.shoesmarket.view.window.wheelpick.EntityOption;
import com.zlzxm.shoesmarket.viewmodel.entity.EntityRepositoryType;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
 * Created by zlz
 * on  4/14/21
 */
public class VMUpdateRepository extends BaseViewModel {

    WareRepository wareRepository = new WareRepository();


    public MutableLiveData<EntityOption> liveSelectType = new MutableLiveData();
    public MutableLiveData<String> liveId = new MutableLiveData();


    public void updateRepository(DialogFragment dialogFragment , FragmentManager fragmentManager,String charge,String name){

        RqWareUpdate rqWareUpdate = new RqWareUpdate(charge,name,liveSelectType.getValue().getId(),liveId.getValue());

        wareRepository.update(rqWareUpdate)
                .compose(RxAndroidHelp.turn(dialogFragment,fragmentManager))
                .subscribe(new BaseCallBack<String>() {
                    @Override
                    protected void succeed(String msg, String s) {

                        liveSucceedToast.setValue(msg);
                    }

                    @Override
                    protected void failed(String msg) {
                        liveErrorToast.setValue(msg);
                    }

                    @Override
                    protected void notLogin() {

                    }
                },throwableCallback);

    }
    //<editor-fold defaultState="collapsed" desc="测试数据">


    // </editor-fold>


}
